#include "container.h"
#include <datasuite.h>


Container::Container(DataSuite *parent) :
    DataContainer(parent)
{
}


QVariant Container::value(int field, int role) const
{
    if (field < 0)
    {
        return QVariant();
    }

    if (role != Qt::DisplayRole && role != Qt::EditRole)
    {
        return QVariant();
    }

    if (field < metaObject()->propertyCount())
    {
        return DataContainer::value(field, role);
    }

    return fieldName(field);
}


bool Container::setValue(int field, const QVariant &value, int role)
{
    if (role != Qt::EditRole || field < 0)
    {
        return false;
    }


    if (field < metaObject()->propertyCount())
    {
        return DataContainer::setValue(field, value, role);
    }

    MetaData* meta = metaData();
    if (!meta)
    {
        return false;
    }

    meta->setItemName(field, value.toString());
    return true;
}
